package com.prs.crm.dao.approval.impl;

import java.util.Collection;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;

import com.prs.crm.context.AppContext;
import com.prs.crm.dao.approval.ShenQingTypeDao;
import com.prs.crm.dao.impl.BaseDaoImpl;
import com.prs.crm.domain.approval.JobType;
import com.prs.crm.domain.approval.ShenQingType;
import com.prs.crm.domain.meeting.MeetSummary;

public class ShenQingTypeDaoImpl extends BaseDaoImpl<ShenQingType> implements ShenQingTypeDao{

	@Override
	public List<ShenQingType> getAllShenQingType() {
		Criteria cri = this.getSession().createCriteria(ShenQingType.class)
		.add(Restrictions.eq("shiType", "启用"));
		cri.add(Restrictions.like("shiyong", "%"+AppContext.getAccountContext().currentUser().getResume().getName()+"%"));
		return cri.list();
	}
	@Override
	public ShenQingType getShenQingType(String name) {
		Criteria criteria = this.getSession().createCriteria(ShenQingType.class)
		.add(Restrictions.eq("name", name));
		List<ShenQingType> list = criteria.list();
		if(list.size() == 0){
			return null;
		}
		return list.get(0);
	}
	@SuppressWarnings("unchecked")
	@Override
	public Collection<ShenQingType> findByJobType(JobType jobType) {
		Criteria criteria=this.getSession().createCriteria(ShenQingType.class);
		criteria.add(Restrictions.eq("jobType", jobType));
		return criteria.list();
	}
	@Override
	public List<ShenQingType> getAllShenQingTypes() {
		Criteria cri = this.getSession().createCriteria(ShenQingType.class);
		return cri.list();
	}
	@Override
	public List<ShenQingType> getShenQingTypeByName(final String name) {
		Criteria criteria = this.getSession().createCriteria(ShenQingType.class)
		.add(Restrictions.eq("name", name));
//		List list = criteria.list();
//		if(list.size() == 0){
//			return null;
//		}
//		return (List<ShenQingType>) list.get(0);
		return criteria.list();
	}

}
